package com.userserver.web;


import com.userserver.mapper.UserMapper;
import domain.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @Author xiaoxi
 * @ProjectName springclouddemo
 * @PackageName com.userserver.web
 * @ClassName UserController
 * @Description TODO
 * @Date 2022/11/14 10:17
 * @Version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/user")
// 热部署配置文件。 当采用 ConfigurationProperties 自动实现热部署
@RefreshScope
public class UserController {


    @Resource
    private UserMapper userMapper;


    @Value("${pattern.dateformat}")
    public String dateformat;

    /**
     * 查询
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public User add(@PathVariable Long id) {
        return userMapper.selectById(id);
    }


    @GetMapping("/getTime")
    public String getTime() {
        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(dateformat));
    }



}
